package com.earl.tbhotbook;

import com.geccocrawler.gecco.annotation.PipelineName;
import com.geccocrawler.gecco.pipeline.Pipeline;
import com.geccocrawler.gecco.request.HttpRequest;
import com.geccocrawler.gecco.scheduler.SchedulerContext;

import java.util.List;

/**
 * Created by 知鹏 on 2018/6/21.
 */
@PipelineName("bookListPipeline")
public class BookListPipeline implements Pipeline<BookList> {


        @Override
        public void process(BookList productList) {


            List<ProductBrief>productLists=productList.getDetails();
            for (ProductBrief productBrief:productLists){
                System.out.println(productBrief.getTitle()+"11111111111111111111111111111111111111"+productBrief.getMoney());
            }

            HttpRequest currRequest = productList.getRequest();
            //下一页继续抓取
            int currPage = productList.getCurrPage();
            int nextPage = currPage + 1;
            int totalPage = productList.getTotalPage();
            if(nextPage <= totalPage) {
                String nextUrl = "";
                String currUrl = currRequest.getUrl();
                nextUrl=currUrl.substring(0,currUrl.length()-1)+nextPage;
                SchedulerContext.into(currRequest.subRequest(nextUrl));
            }
        }
        }




